<?php
    //ini_set('display_errors',1);
    include ("lib_db.php");
	include("function.php");
	include("config.php");
	if(!isset($_SESSION)){ session_start();}
if(!isset($_SESSION['user'])){
header('location:login.php');
exit();
}else{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xlmns="http://www.w3.org/1999/xhtml">
<head><?php include("view/head.php");?></head>

<body>
<div class="wrapper">
	<div class="header"><?php include ("view/header.php");?></div>
	<div class="clear"></div>
	<div class="content">
		<div class="menu"><?php include("view/menu.php");?></div>
		<div class="center_content">
			<div class="left_content"> <?php include ("view/left_content.php");?></div>

<?php 

if(isset($_REQUEST['id'])){
	$id=$_REQUEST['id'];
	$sql="select * from book where idBook='$id'";
	$query=select_one($sql);
	$idCategory1=$query['idCategory'];
	$Name=$query['Name'];
	$Author=$query['Author'];
	$Translator=$query['Translator'];
	$Paperboard=$query['Paperboard'];
	$Size=$query['Size'];
	$Publisher=$query['Publisher'];
	$PageNumber=$query['PageNumber'];
	$Weight=$query['Weight'];
	$SalePrice=$query['SalePrice'];
	$CoverPrice=$query['CoverPrice'];
	$Number=$query['Number'];
	$SaleOff=$query['SaleOff'];
	$ImgCover=$query['ImgCover'];
	$Description=$query['Description'];
	
	$sql1= "select * from category_book where idCategory= '$idCategory1'";
	$query1=select_one($sql1);
	$idCategory=$query1['idCategory'];
	$NameCategory=$query1['NameCategory'];
	
} 
 if(isset($_POST['update'])){
	$sSalePrice="NULLs";
    if(isset($_REQUEST['Name'])){$Name=$_REQUEST['Name'];}
    if(isset($_REQUEST['mota'])){$Description=$_REQUEST['mota'];}
	if(isset($_REQUEST['SalePrice'])){$SalePrice=$_REQUEST['SalePrice'];}
	
	
	if(isset($_REQUEST['nsp'])){$idCategory=$_REQUEST['nsp'];}
	if(isset($_REQUEST['tensach'])){$tensach=$_REQUEST['tensach'];}
	if(isset($_REQUEST['tacgia'])){$tacgia=$_REQUEST['tacgia'];}
	if(isset($_REQUEST['dichgia'])){$dichgia=$_REQUEST['dichgia'];}
	if(isset($_REQUEST['hinthucbia'])){$hinthucbia=$_REQUEST['hinthucbia'];}
	if(isset($_REQUEST['nhaxuatban'])){$nhaxuatban=$_REQUEST['nhaxuatban']; }
	if(isset($_REQUEST['sotrang'])){$sotrang=$_REQUEST['sotrang'];}
	if(isset($_REQUEST['trongluong'])){$trongluong=$_REQUEST['trongluong'];}
	if(isset($_REQUEST['giaban'])){$giaban=$_REQUEST['giaban'];}
	if(isset($_REQUEST['giabia'])){$giabia=$_REQUEST['giabia'];}
	if(isset($_REQUEST['kichco'])){$kichco=$_REQUEST['kichco'];}
	if(isset($_REQUEST['giamgia'])){$giamgia=$_REQUEST['giamgia'];}
	if(isset($_REQUEST['soluong'])){$soluong=$_REQUEST['soluong'];}
	if(isset($_REQUEST['mota'])){$mota=$_REQUEST['mota'];}
	if(isset($_REQUEST['ImgCover']))// kiểm tra xem tồn tài  giá trị ImgCover trên URL không	
	{
		$image1=$_REQUEST['ImgCover'];	//Gắn giá trị đó cho biến image1
		if($image1!="")// Nếu image1 khác rỗng thì
		{
			$ImgCover=$image1; // gắn giá trị biến image1 cho ImgCover cuối cùng giá trị trả về là ImgCover
		}
	}
	
        $sql="update book set Name='$tensach', Author='$tacgia', Translator='$dichgia', Paperboard='$hinthucbia',
		Size='$kichco', Publisher='$nhaxuatban', PageNumber='$sotrang', Weight='$trongluong', SalePrice='$giaban', 
		CoverPrice='$giabia', Number='$soluong', SaleOff='$giamgia', ImgCover='$ImgCover', Description='$mota', idCategory='$idCategory'
		where idBook='$id'";// echo $sql;exit();
        $query=exec_update($sql);//echo "<pre>";print_r($sql);echo "</pre>";exit();
		header("location:index.php");
    
 
}
 ?> 
			<div class="right_content">
				<h2>Sửa sản phẩm</h2>
                <form action="" method="POST">              
    				<table>
                     
						<tr class="title">
                            <td><span>Tên nhóm sản phẩm:</span></td>
                            <td><select class="nsp" name="nsp" style="width: 250px; "><?php// echo glist_option();//   để ra để hiên sp để chọn //id="nhomsp" ?>
								<option value="<?php echo $idCategory;?>"><?php echo $NameCategory;?></option>
							</select></td>
                        </tr>

                        <tr class="title">
                            <td><span>Tên Sách:</span></td>
                            <td><input type="text" value="<?php echo $Name;?>" style="width:240px" name="tensach"></td>
                        </tr>
						
						<tr class="title">
                            <td><span>Tắc Giả:</span></td>
                            <td><input type="text" value="<?php echo $Author;?>" style="width:240px" name="tacgia"></td>
                        </tr>
						<tr class="title">
                            <td><span>Dịch Giả:</span></td>
                            <td><input type="text" value="<?php echo $Translator;?>" style="width:240px" name="dichgia"></td>
                        </tr><tr class="title">
                            <td><span>Hình Thức Bìa:</span></td>
                            <td><input type="text" value="<?php echo $Paperboard;?>" style="width:240px" name="hinthucbia"></td>
                        </tr>
                     
						<tr class="title">
                            <td><span>Nhà xuất bản:</span></td>
                            <td><input type="text" value="<?php echo $Publisher;?>" style="width:240px" name="nhaxuatban"></td>
                        </tr>
						<tr class="title">
                            <td><span>Số Trang:</span></td>
                            <td><input type="text" value="<?php echo $PageNumber;?>" style="width:240px" name="sotrang"></td>
                        </tr>
						<tr class="title">
                            <td><span>Trọng Lượng:</span></td>
                            <td><input type="text" value="<?php echo $Weight;?>" style="width:240px" name="trongluong"></td>
                        </tr>
						<tr class="title">
                            <td><span>Giá Bán:</span></td>
                            <td><input type="text" value="<?php echo $SalePrice;?>" style="width:240px" name="giaban"></td>
                        </tr>
						<tr class="title">
                            <td><span>Giá Bìa:</span></td>
                            <td><input type="text" value="<?php echo $CoverPrice;?>" style="width:240px" name="giabia"></td>
                        </tr>
							<tr class="title">
                            <td><span>Kích cỡ:</span></td>
                            <td><input type="text" value="<?php echo $Size;?>" style="width:240px" name="kichco"></td>
                        </tr>
						<tr class="title">
                            <td><span>Giảm giá:</span></td>
                            <td><input type="text" value="<?php echo $SaleOff;?>" style="width:240px" name="giamgia"></td>
                        </tr>
						
						
						<tr class="title">
                            <td><span>Sô lượng:</span></td>
                            <td><input type="text" value="<?php echo $Number;?>" style="width:240px" name="soluong"></td>
                        </tr>
						
                        <tr class="title">
                            <td><span>Mô tả sản phẩm:</span></td>
                            <td><textarea style="background-color:#E0E0EB;width: 250px; height: 80px;" name="mota"><?php echo $Description;?></textarea></td>
                        </tr>
						
                       
                        <tr class="title">
                            <td><span>Hình ảnh sản phẩm:</span></td>
                            <td><div class="clear"><?php echo $ImgCover;?></div><input type="file" name="ImgCover" value="Choose File" style="width:244px" /></td>
                        </tr>
						 
                        
                        <tr class="value">
                            <td></td>
                            <td>
                                <input type="reset" value="Nhập lại" name="reset"/>
                                <input type="submit" value="Thêm" name="update"/>
                            </td>
                        </tr>
                    </table>
                </form>
		  </div>
		</div>
	</div>
	<div class="clear"></div>
	<div class="footer">
		<div class="left_ft">
			<span>IN ADMIN PANEL | Powered by</span>
			<a href="http://indeziner.com">INDEZINER</a>
		</div>
		<div class="right_ft">
			<a href="http://indeziner.com"><img border="0" title="" alt="" src="ImgCover/indeziner_logo.gif"></a>
		</div>
	</div>
</div>
</body>
</html>
<?php } ?>